package part1.api.collection;

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        String str = "   helloworldlo  ";
        //字符串长度
        System.out.println(str.length());

        //去除两头空格
        str = str.trim();
        System.out.println(str);

        //转大小写
        str = str.toUpperCase();
        System.out.println(str);
        str = str.toLowerCase();
        System.out.println(str);

        //判断是否以某某字符串开头或结尾
        boolean a = str.startsWith("af");
        System.out.println(a);
        boolean b = str.endsWith("af");
        System.out.println(b);

        //返回指定下标的字符
        char ch = str.charAt(3);
        System.out.println(ch);

        //返回指定字符串的下标
        int in = str.indexOf("llo");
        System.out.println(in);
        int in1 = str.indexOf("lo",4);
        System.out.println(in1);
        int in2 = str.lastIndexOf("lo");
        System.out.println(in2);

        //截取指定返回的字符串
        String substr = str.substring(2,8);
        System.out.println(substr);

        //转字符串
        String str2 = String.valueOf(5);
        System.out.println(str2);

        //判断字符串是否满足给定的正则表达式的格式要求
        String regex = "[a-zA-Z0-9_]+@+[a-zA-Z0-9]+(\\.[a-zA-Z]+)+";
        String mail = "wangkj@tedu.com";
        boolean matches = mail.matches(regex);
        System.out.println(matches);

        //将字符串满足正则的部分全部替换成给定的字符串
        String str3 = "你TMD的大SB草";
        str = str3.replaceAll("(TMD|SB|草)+","*");
        System.out.println(str);

        //将字符串按照满足正则的部分拆分成字符串数组
        String str4 = "abc.def.ghi";
        String[] strs = str4.split("\\.");
        System.out.println(Arrays.toString(strs));
    }
}
